package start;

import java.util.Scanner;

public class T27 {
    public static void main(String[] args) {
        int[] nums = {1, 2, 3, 2, 2, 4, 5, 6};
        int val = 2;
        int r=removeElement(nums, val);
        System.out.println(r);
        print(nums);


    }

    public static int removeElement(int[] nums, int val) {
//        int   快    慢

        int fast=0;
        int slow=0;

        while(fast<nums.length){
            if(nums[fast]!=val){
                nums[slow++]=nums[fast++];
            }else {
                fast++;
            }
        }
        return slow;
    }



    public static int [] ScIntArray(int n){
        int [] nums =new int[n];
        Scanner scanner=new Scanner(System.in);
        for(int i=0;i<n;i++){
            if(scanner.hasNextInt()){
                nums[i]=scanner.nextInt();
            }
        }
        return nums;
    }
    public static void print(int []nums){
        String str="[";
        for (int i=0;i<nums.length;i++){
            str+=nums[i];
            if(i==nums.length-1){
                str+="]";
            }else{
                str+=",";
            }
        }
        System.out.println(str);
    }
}
